package com.lse_api.control;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lse_api.entity.ProjectLog;
import com.lse_api.service.ProjectLogService;
import com.lse_api.utils.PageUtil;
import com.lse_api.utils.ReturnMsg;
import com.lse_api.utils.Status;
import com.lse_api.utils.pdfutil.stringutil.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import com.lse_api.exception.LseException;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 项目日志 前端控制器
 * </p>
 *
 * @author 祁雪
 * @since 2020-05-11
 */
@Controller
@RequestMapping("/lseapi/api/projectLog")
public class ProjectLogController extends LseException implements ReturnMsg {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private ProjectLogService projectLogService;

    /**
     * 根据项目ID 读取日志列表包括该条日志的用户信息
     * project: 项目ID
     *
     * @return
     */
    @RequestMapping(value = "/getLogs")
    @ResponseBody
    public Status getLogs() {

        String projectId = request.getParameter("project");

        String pageNo = request.getParameter("pageNo");
        String pageSize = request.getParameter("pageSize");

        if (StringUtils.isEmpty(projectId)) {
            return Status.error(API_PROJECT_ID);
        }

        Map<String, Integer> map = PageUtil.getPage(pageNo, pageSize);

        PageHelper.startPage(map.get("pageNo"), map.get("pageSize"));

        List<ProjectLog> list = projectLogService.getLos(projectId);

        PageInfo<ProjectLog> pageInfo = new PageInfo<>(list);

        return Status.success(pageInfo);

    }
}

